package com.um.jdy.mp.user.controller;

import com.um.jdy.common.member.enums.CodeKey;
import com.um.jdy.mp.user.entity.dto.MobileDTO;
import com.um.jdy.mp.user.entity.dto.BindWXDTO;
import com.um.jdy.mp.user.entity.dto.ResetPasswordDTO;
import com.um.jdy.mp.user.entity.vo.SigninVO;
import com.um.jdy.mp.user.manager.MobileManager;
import com.um.springboot.starter.orm.entity.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

/**
 * 手机号码方式-注册及登录
 *
 * @author cs
 * 日期 2023/5/23
 * 版权所有 广州优匠科技有限公司
 */
@Api(tags = "手机号")
@RestController
@RequestMapping("/api/v1/user/mobile")
@Validated
public class MobileController {

    @Autowired
    MobileManager mobileManager;

    /**
     * 绑定微信
     * @param bindwxDTO
     * @return
     */
    @ApiOperation(value = "绑定微信")
    @PostMapping("/bindwx")
    public Response<SigninVO> bindwx(@RequestBody BindWXDTO bindwxDTO) {
        return Response.success(mobileManager.bindwx(bindwxDTO));
    }

    /**
     * 手机验证码登录
     * @param mobileDTO
     * @return
     */
    @ApiOperation(value = "手机验证码登录")
    @PostMapping("/signin")
    public Response<SigninVO> signin(@RequestBody MobileDTO mobileDTO) {
        return Response.success(mobileManager.signin(mobileDTO));
    }

    /**
     * 发送验证码
     * @param mobile
     * @param key
     * @return
     */
    @ApiOperation(value = "发送验证码")
    @GetMapping("/send_code")
    public Response sendCode(@ApiParam(value = "手机号") @NotEmpty String mobile,
                             @ApiParam(value = "验证码标识") @NotNull String key) {
        CodeKey codeKey = CodeKey.get(key);
        mobileManager.sendCode(codeKey, mobile);
        return Response.success();
    }

    /**
     * 验证原手机号
     * @param mobileDTO
     * @return
     */
//    @ApiOperation(value = "验证原手机号")
//    @PostMapping("/verify")
//    @SaCheckLogin
//    public Response verify(@RequestBody MobileDTO mobileDTO) {
//        mobileManager.verify(mobileDTO);
//        return Response.success();
//    }

    /**
     * 绑定新手机号
     * @param mobileDTO
     * @return
     */
//    @ApiOperation(value = "绑定新手机号")
//    @PostMapping("/bind")
//    @SaCheckLogin
//    public Response bind(@RequestBody MobileDTO mobileDTO) {
//        return mobileManager.bind(mobileDTO) ? Response.success() : Response.failed();
//    }

    /**
     * 重置密码
     *
     * @return
     */
    @ApiOperation(value = "找回/重置密码")
    @PostMapping("/reset_password")
    public Response resetPassword(@RequestBody ResetPasswordDTO resetPasswordDTO) {
        return mobileManager.resetPassword(resetPasswordDTO);
    }
}
